from django.contrib import admin
from .models import ChatRoom, ChatMessage, ChatRoomMember, MessageReadStatus

@admin.register(ChatRoom)
class ChatRoomAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'room_type', 'created_at', 'updated_at']
    list_filter = ['room_type', 'created_at']
    search_fields = ['name']
    readonly_fields = ['created_at', 'updated_at']

@admin.register(ChatRoomMember)
class ChatRoomMemberAdmin(admin.ModelAdmin):
    list_display = ['id', 'room', 'user', 'joined_at', 'is_admin']
    list_filter = ['is_admin', 'joined_at']
    search_fields = ['user__username', 'user__phone', 'room__name']
    readonly_fields = ['joined_at']

@admin.register(ChatMessage)
class ChatMessageAdmin(admin.ModelAdmin):
    list_display = ['id', 'room', 'sender', 'message_type', 'content', 'created_at', 'is_read']
    list_filter = ['message_type', 'is_read', 'created_at']
    search_fields = ['content', 'sender__username', 'sender__phone']
    readonly_fields = ['created_at']
    raw_id_fields = ['room', 'sender']

@admin.register(MessageReadStatus)
class MessageReadStatusAdmin(admin.ModelAdmin):
    list_display = ['id', 'message', 'user', 'read_at']
    list_filter = ['read_at']
    search_fields = ['user__username', 'user__phone']
    readonly_fields = ['read_at']
    raw_id_fields = ['message', 'user']
